package com.hzlh.filter;


import com.hzlh.configuration.cas.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @Description: WEB拦截处理
 * @Author: linker_zhang
 * @Date: Created in 2020/5/13 19:18
 * @Version:1.0.0
 */
@Configuration("webConfiguration")
public class WebConfiguration extends WebMvcConfigurerAdapter {

    @Value("${cors.allowOrgin}")
    private String allowOrgin;
    @Value("${spring.profiles.active}")
    private String profiles;

    /**
     * 过滤器注册
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new CorsFilter(allowOrgin, profiles));
        registration.addUrlPatterns("/*");
        registration.setName("corsFilter");
        registration.setOrder(0);
        return registration;

    }


//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new UserLoginInterceptor())
//                .addPathPatterns("/**")
//                .excludePathPatterns("/h5/**")
//                .excludePathPatterns("/hello")
//                .excludePathPatterns("/weChatApplet/**")
//                .excludePathPatterns("/img/upload");
//    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }

}
